/*
 * PennTreebankIterator.java
 *
 * Created on March 4, 2007, 9:24 PM
 *
 */

package galronnlp.perceptron;

import galronnlp.io.PennTreeReader;
import galronnlp.util.SymbolGenerator;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Iterator;

/**
 * 
 * @author Dennis N. Mehay
 */
public class PennTreebankIterator implements Iterator<Node> {
    
    private PennTreeReader ptReader = null;
    private int size = 0;
    private int cursor = 0;
    private SymbolGenerator gen;
    
    /** Creates a new instance of PennTreebankIterator */
    public PennTreebankIterator(String treebank, SymbolGenerator gen, int size) {
        try {
            this.size = size;
            this.gen = gen;
            this.ptReader = new PennTreeReader(new BufferedReader(new FileReader(treebank)), gen);
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public boolean hasNext() {
        return (this.cursor < this.size);
    }

    public Node next() {
        if(this.cursor < this.size) {
            this.cursor++;
            return ptReader.readNodeTree();
        } else {
            ptReader.close();
            return null;
        }       
    }

    public int indexOf() {
        return (this.cursor-1);
    }
    
    public void remove() { System.err.println("Nope! Not implemented!"); }
    
}
